﻿using System;

namespace OneSystems.Helpers
{
    public class EnvironmentNotSupportedException : System.Exception
    {
        public EnvironmentNotSupportedException() : base() { }
        public EnvironmentNotSupportedException(string message) : base(message) { }
        public EnvironmentNotSupportedException(string message, Exception innerException) : base(message, innerException) { }
    }

    /// <summary>
    /// This enum represents the environments set up for the solution in Visual Studio.
    /// </summary>
    public enum CurrentEnvironment
    {
        Development = 0,
        Testing,
        Staging,
        Production
    }

    public class EnvironmentState
    {
        /// <summary>
        /// This property returns the current database connection string dependant upon the selected environment.
        /// </summary>
        public static string CurrentConnectionString
        {
            get
            {
                string connectionString = string.Empty;
                switch (CurrentEnvironment)
                {
                    case CurrentEnvironment.Development:
                        connectionString = "Data Source=BASEMENT;Initial Catalog=DebtSystem;Integrated Security=True;Pooling=False";
                        break;
                    case CurrentEnvironment.Testing:
                        connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionStrings.Testing"].ConnectionString;
                        break;
                    case CurrentEnvironment.Staging:
                        connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionStrings.Staging"].ConnectionString;
                        break;
                    case CurrentEnvironment.Production:
                        connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionStrings.Production"].ConnectionString;
                        break;
                    default:
                        throw new EnvironmentNotSupportedException();
                }
                return connectionString;
            }
        }

        /// <summary>
        /// This property returns an enum representing the current selected environment.
        /// </summary>
        public static CurrentEnvironment CurrentEnvironment
        {
            get
            {
                CurrentEnvironment returnValue;

#if(DEVELOPMENT)
				returnValue = CurrentEnvironment.Development;
#elif(TESTING)
			returnValue = CurrentEnvironment.Testing;
#elif(STAGING)
			returnValue = CurrentEnvironment.Staging;
#else
                returnValue = CurrentEnvironment.Production;
#endif
                return returnValue;
            }
        }
    }

}